import { mapState ,mapMutations} from 'vuex';
export default {
	data() {
		return {
			user : []
		}
	},
  computed: {
    	...mapState(['hasLogin', 'userInfo'])
    },
	created(){
		// this.get_user();
	},
	methods: {
      ...mapMutations(['login','logout']),
      get_user(){ 
        let user = uni.getStorageSync('user')||[];
        this.user = user;
		 },
     auto_login() {
     	let userInfo = uni.getStorageSync('userInfo') || '';
     	if (userInfo.id) {
     		this.req({
     			url: this.site_url + 'api/user/auto_login',
     			method: 'GET',
     			data: {
     				uid: userInfo.id
     			},
     			success: res => {
     				let ret = res.data;
     				if (ret.code == 1) {
     					this.login(ret.data);
     				}else{
              
     					this.logout();
     					if(ret.code == -2)
     					{
     						this.showMsg(ret.msg);
     					}else{
     						this.showMsg('登录态失效');
     					}
     					setTimeout(() => {
     						this.$r('/pages/public/login');
     					}, 2000);
     					
     				}
     			},
     			fail: err => {
     				this.showMsg('网络错误');
     			}
     		});
     	} else {
     	}
     },

	}

}
